package com.ruoyi.miaomiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.miaomiao.domain.AdvertismentPicture;
import com.ruoyi.miaomiao.service.IAdvertismentPictureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宣传图Controller
 * 
 * @author ruoyi
 * @date 2022-08-10
 */
@RestController
@RequestMapping("/miaomiao/advertismentpicture")
public class AdvertismentPictureController extends BaseController
{
    @Autowired
    private IAdvertismentPictureService advertismentPictureService;

    /**
     * 查询宣传图列表
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvertismentPicture advertismentPicture)
    {
        startPage();
        List<AdvertismentPicture> list = advertismentPictureService.selectAdvertismentPictureList(advertismentPicture);
        return getDataTable(list);
    }

    /**
     * 导出宣传图列表
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:export')")
    @Log(title = "宣传图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvertismentPicture advertismentPicture)
    {
        List<AdvertismentPicture> list = advertismentPictureService.selectAdvertismentPictureList(advertismentPicture);
        ExcelUtil<AdvertismentPicture> util = new ExcelUtil<AdvertismentPicture>(AdvertismentPicture.class);
        util.exportExcel(response, list, "宣传图数据");
    }

    /**
     * 获取宣传图详细信息
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:query')")
    @GetMapping(value = "/{advertismentPictureId}")
    public AjaxResult getInfo(@PathVariable("advertismentPictureId") Long advertismentPictureId)
    {
        return AjaxResult.success(advertismentPictureService.selectAdvertismentPictureByAdvertismentPictureId(advertismentPictureId));
    }

    /**
     * 新增宣传图
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:add')")
    @Log(title = "宣传图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvertismentPicture advertismentPicture)
    {
        return toAjax(advertismentPictureService.insertAdvertismentPicture(advertismentPicture));
    }

    /**
     * 修改宣传图
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:edit')")
    @Log(title = "宣传图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvertismentPicture advertismentPicture)
    {
        return toAjax(advertismentPictureService.updateAdvertismentPicture(advertismentPicture));
    }

    /**
     * 删除宣传图
     */
    @PreAuthorize("@ss.hasPermi('miaomiao:advertismentpicture:remove')")
    @Log(title = "宣传图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertismentPictureIds}")
    public AjaxResult remove(@PathVariable Long[] advertismentPictureIds)
    {
        return toAjax(advertismentPictureService.deleteAdvertismentPictureByAdvertismentPictureIds(advertismentPictureIds));
    }
}
